package com.vodone.v1pin.userInfo.delegate
{
	import com.vodone.v1pin.userInfo.vo.AreaVO;
	import com.vodone.v1pin.userInfo.vo.InfoVO;
	
	import mx.collections.ArrayCollection;
	import mx.utils.StringUtil;

	public class UserInfoUtil
	{
		public static function isTrueMobile(str:String):Boolean
		{
			var re:RegExp=/(^1[3,5,8]{1}[0-9]{1}[0-9]{8}$)/;
			return null != re.exec(StringUtil.trim(str));
		}
		public static function isTruePhone(str:String):Boolean
		{
			var re:RegExp=/0\d{2,3}-\d{5,9}|0\d{2,3}-\d{5,9}/;
			return null != re.exec(StringUtil.trim(str));
		}
		public static function isTrueEmail(str:String):Boolean
		{
			var re:RegExp = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
			return null != re.exec(StringUtil.trim(str));
		}
		public static function isTruePostCode(str:String):Boolean
		{
			var re:RegExp = /[1-9]\d{5}(?!\d)/;
			return null != re.exec(StringUtil.trim(str));
		}
		public static function getAreaListFromObj(obj:Object):Array
		{
			var list:Array = [];
			if(obj && obj is Array)
			{
				var arr:Array = obj as Array;
				if(arr && arr.length > 0)
				{
					for(var i:int = 0; i< arr.length ; i++)
					{
						list.push(getAreaItem(arr[i]));
					}
				}
			}
			return list;
		}
		public static function getAreaItem(obj:Object):AreaVO
		{
			var item:AreaVO = new AreaVO();
			if(obj)
			{
				if(obj.hasOwnProperty("id"))
				{
					item.id = obj["id"];
				}
				if(obj.hasOwnProperty("name"))
				{
					item.name = obj["name"];
				}
			}
			return item;
		}
		
		public static function getInfoVOFromObj(obj:Object):InfoVO
		{
			var item:InfoVO = new InfoVO();
			
			if(obj)
			{
				if(obj.hasOwnProperty("areaCode"))
				{
					item.areaCode = obj["areaCode"];
				}
				if(obj.hasOwnProperty("birthday"))
				{
					item.birthday = obj["birthday"];
				}
				
				if(obj.hasOwnProperty("cityCode"))
				{
					item.cityCode = obj["cityCode"];
				}
				if(obj.hasOwnProperty("loginname"))
				{
					item.loginname = obj["loginname"];
				}
				
				if(obj.hasOwnProperty("love"))
				{
					item.love = obj["love"];
				}
				if(obj.hasOwnProperty("mail"))
				{
					item.mail = obj["mail"];
				}
				
				if(obj.hasOwnProperty("mailState"))
				{
					item.mailState = obj["mailState"];
				}
				if(obj.hasOwnProperty("mobile"))
				{
					item.mobile = obj["mobile"];
				}
				if(obj.hasOwnProperty("mobileState"))
				{
					item.mobileState = obj["mobileState"];
				}
				if(obj.hasOwnProperty("provinceCode"))
				{
					item.provinceCode = obj["provinceCode"];
				}
				if(obj.hasOwnProperty("sex"))
				{
					item.sex = obj["sex"];
				}
				if(obj.hasOwnProperty("trueName"))
				{
					item.trueName = obj["trueName"];
				}
			}
			return item;
		}
	}
}